<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::namespace('Api')->get('/test',function (Request $request){
    return 5555;
});
Route::namespace('Api')->prefix('v1')->middleware('cors','jwt.role:user')->group(function () {


    Route::get('/image/{path}/{filename}', function ($path,$filename) {
        $path = 'public/images/'.$path.'/'.$filename; // 假设图片位于 storage/app/public/image.jpg
        if (Storage::disk('local')->exists($path)) {
            $file = Storage::disk('local')->get($path);
            $type = Storage::disk('local')->mimeType($path);
            $response = Response::make($file, 200);
            $response->header("Content-Type", $type);
            return $response;
        }
        abort(404);
    });

    ////设置响应头，inline:表示在线预览,后面是文件的名字
    //        response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(fileName, "UTF-8"));
    //        //设置文件的大小 （ios不设置无法正常播放视频）
    //        response.setHeader("Content-Length", String.valueOf(fileLength));
    //        //文件格式
    //        response.setContentType("video/mp4");


    Route::get('/video/{path}/{filename}', function ($path,$filename) {
        $path = 'public/video/'.$path.'/'.$filename; // 假设图片位于 storage/app/public/image.jpg
        if (Storage::disk('local')->exists($path)) {
            $file = Storage::disk('local')->get($path);
            $type = Storage::disk('local')->mimeType($path);
            $fileLength = Storage::size($path);
            $response = Response::make($file, 200);
            $response->header("Content-Disposition","inline;filename=" . $filename);
            $response->header("Content-Length", $fileLength);
            $response->header("Content-Type", "video/mp4");
            return $response;
        }
        abort(404);
    });

    Route::post('/users','UserController@store')->name('users.store');
    Route::post('/login','UserController@login')->name('users.login');  //用户 登录
    Route::post('/login1','UserController@login1')->name('users.login1');  //用户 登录


    Route::get('/getOpenidFromCode','WechatminiController@getOpenidFromCode');
    Route::get('/getInfoFromOpenid','UserController@getInfoFromOpenid');
    Route::post('/register','UserController@register');


    Route::get('/getAbout','IndexController@getAbout')->name('index.getAbout');


    Route::get('/getJsConfig','WechatController@getJsConfig')->name('users.getJsConfig'); //注入配置参数


    Route::get('/getUserActivityList','ActivityController@getUserActivityList')->name('users.get_activity'); //获取活动列表
    Route::get('/getUserActivityDetail','ActivityController@getUserActivityDetail')->name('users.get_activity_detail'); //获取活动详情
    Route::get('/getCommentList','ActivityController@getCommentList')->name('users.get_activity_comment'); //获取活动评论




    Route::any('/notify','WechatPayController@notify')->name('wechatpay.notify'); //支付回调

    Route::post('/upload', 'UploadController@store');//图片上传



    Route::middleware('api.refresh','user.status')->group(function () {

        Route::post('/sendCode','UserController@sendCode')->name('users.sendCode'); //发送手机验证码
        Route::post('/checkCode','UserController@checkCode')->name('users.checkCode'); //验证手机验证码

        Route::post('/getPhone','UserController@getPhone');

        //用户信息
        Route::get('/users/{user}','UserController@show')->name('users.show');
        //用户退出
        Route::get('/logout','UserController@logout')->name('users.logout');


        //保存手机号码
        Route::post('/savePhone','UserController@savePhone')->name('users.phone'); //保存用户手机号码





        //Route::post('/upload', 'UploadController@store');//图片上传

        Route::post('/addOrder','UserController@addOrder')->name('users.addOrder'); //生成订单
        Route::get('/cancelOrder','UserController@cancelOrder')->name('users.cancelOrder'); //取消订单
        Route::post('/refundOrder','UserController@refundOrder')->name('users.addOrder'); //发起退款
        Route::post('/payOrder','UserController@payOrder')->name('users.payOrder'); //去支付




        Route::post('/pay_order','UserController@pay_order')->name('users.pay_order'); //发起支付





        Route::post('/addComment','ActivityController@addComment')->name('users.add_comment'); //获取活动评论
        Route::post('/addFavorite','ActivityController@addFavorite')->name('users.add_favorite'); //添加收藏
        Route::post('/deleteFavorite','ActivityController@deleteFavorite')->name('users.delete_favorite'); //添加收藏
        Route::get('/getFavoriteList','ActivityController@getFavoriteList')->name('users.getFavoriteList'); //添加收藏




        Route::get('/getUserOrderList','UserController@getUserOrderList')->name('users.getOrderList'); //用户获取订单记录
        Route::get('/getUserOrderDetail','UserController@getUserOrderDetail')->name('users.getUserOrderDetail'); //用户获取订单详情
        Route::get('/getMyQrList','UserController@getMyQrList')->name('users.getMyQrList'); //用户获取核销码
        Route::get('/getCheckStatus','UserController@getCheckStatus')->name('users.getCheckStatus'); //获取核销状态
        Route::get('/QrCodeRefresh','UserController@QrCodeRefresh')->name('users.QrCodeRefresh'); //刷新二维码






        Route::get('/getLunbo','IndexController@getLunbo')->name('index.getLunbo'); //获取轮播图





    });








});








